{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
    <h1>资产列表</h1>
    {% if current_user.is_authenticated %}
    <a href="{{ url_for('main.add_asset') }}" class="btn btn-primary">添加资产</a>
    {% endif %}
</div>

{% if assets %}
<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th>资产名称</th>
                <th>序列号</th>
                <th>类型</th>
                <th>状态</th>
                <th>位置</th>
                <th>负责人</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for asset in assets %}
            <tr>
                <td>{{ asset.name }}</td>
                <td>{{ asset.serial_number }}</td>
                <td>{{ asset.asset_type }}</td>
                <td>
                    {% if asset.status == 'Active' %}
                        <span class="badge bg-success">在用</span>
                    {% elif asset.status == 'Inactive' %}
                        <span class="badge bg-secondary">闲置</span>
                    {% elif asset.status == 'In Repair' %}
                        <span class="badge bg-warning">维修中</span>
                    {% elif asset.status == 'Retired' %}
                        <span class="badge bg-danger">已报废</span>
                    {% else %}
                        <span class="badge bg-info">{{ asset.status }}</span>
                    {% endif %}
                </td>
                <td>{{ asset.location or '未指定' }}</td>
                <td>{{ asset.assigned_to.username if asset.assigned_to else '未分配' }}</td>
                <td>
                    {% if current_user.is_authenticated %}
                    <a href="{{ url_for('main.edit_asset', id=asset.id) }}" class="btn btn-sm btn-outline-primary">编辑</a>
                    <form method="POST" action="{{ url_for('main.delete_asset', id=asset.id) }}" class="d-inline">
                        <button type="submit" class="btn btn-sm btn-outline-danger" 
                                onclick="return confirm('确定要删除这个资产吗？')">删除</button>
                    </form>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="alert alert-info">
    <p>暂无资产记录。</p>
    {% if current_user.is_authenticated %}
    <a href="{{ url_for('main.add_asset') }}" class="btn btn-primary">添加第一个资产</a>
    {% endif %}
</div>
{% endif %}
{% endblock %}